<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Log;
use App\Models\BooksAutoUpdate;

class AutoUpdate extends Command {

    protected $name = 'AutoUpdate';//命令名称

    protected $description = '小说自动更新'; // 命令描述

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //获取自动更新数据
        $data = BooksAutoUpdate::select(['id','book_id','book_name'])->where('is_update','0')->first();
        if (!empty($data)){
            BooksAutoUpdate::where('id',$data['id'])->update(array('is_update' => 1,'updated_at'=>date('Y-m-d H:i:s')));
            Log::info('自动更新：'.json_encode($data));
            //scrapy crawl bookChapter -a bookName=元尊
            exec('cd /opt/shell && /usr/bin/sudo /bin/sh chapterUpdate.sh '.$data['name']);
        }
    }

}